package com.duan.dao.role;

import com.duan.dao.baseDao;
import com.duan.pojo.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RoleDaoImpl implements RoleDao {
    //获取角色列表
    public List<Role> getRoleList(Connection connection) throws SQLException {

        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        List<Role> roleList = new ArrayList<Role>();

        if(connection != null){
            String sql = "select * from smbms_role";
            Object [] params = {};

            resultSet = baseDao.execute(connection, sql, params, resultSet, preparedStatement);

            while(resultSet.next()){
                Role role = new Role();
                role.setId(resultSet.getInt("id"));
                role.setRoleCode(resultSet.getString("roleCode"));
                role.setRoleName(resultSet.getString("roleName"));
                roleList.add(role);
            }
            baseDao.closeResource(null, preparedStatement, resultSet);
        }
        return roleList;
    }
}
